<HTML><HEAD><TITLE>C(?Input, ?Token, ?Rest)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Term Manipulation</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>C(?Input, ?Token, ?Rest)</H1>
Specifies how DCG grammar rules get a token from their input.


<DL>
<DT><EM>Input</EM></DT>
<DD>A List or a variable.
</DD>
<DT><EM>Token</EM></DT>
<DD>A term or a variable.
</DD>
<DT><EM>Rest</EM></DT>
<DD>A List or a variable.
</DD>
</DL>
<H2>Description</H2>
   This predicate is only useful in connection with definite clause grammar
   rules (DCG). There is a global default definition of 'C'/3 which
   consists of the single clause 'C'([Token|Rest], Token, Rest).  The Input
   argument represents the parsing input before consuming Token and Rest is
   the input after consuming Token.

<P>
   DCGs normally operate on lists of tokens.  However, by redefining 'C'/3,
   it is possible to let them manipulate other data structures.  The
   example shows how to parse directly from an I/O stream.

<P>

<H3>Modes and Determinism</H3><UL>
<LI>C(+, -, -) is semidet
<LI>C(-, +, +) is det
</UL>
<H3>Fail Conditions</H3>
Fails if Input is not a non-empty list
<H2>Examples</H2>
<PRE>
[eclipse 1]: [user].
 sentence --&gt; noun, [is], adjective.
 noun --&gt; [prolog] ; [lisp].
 adjective --&gt; [boring] ; [great].
user       compiled traceable 560 bytes in 0.05 seconds

yes.
[eclipse 2]: phrase(sentence, [prolog,is,great], []).

yes.
[eclipse 3]: [user].
:- local 'C'/3.       % to avoid a redefinition warning
'C'(Stream-Pos0, Token, Stream-Pos1) :-
        seek(Stream, Pos0),
        read_string(Stream, " ", _, TokenString),
        atom_string(Token, TokenString),
        at(Stream, Pos1).
user       compiled traceable 308 bytes in 0.00 seconds

yes.
[eclipse 4]: open(string("prolog is great"), read, S),
             phrase(sentence, S-0, S-End).
S = 9
End = 15     More? (;)
yes.



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/control/phrase-3.html">phrase / 3</A>
</BODY></HTML>
